package leetcom.ncom49;

import java.util.HashMap;

public class Ex5708 {
    public int countNicePairs(int[] nums) {
        int [] rev = new int[nums.length];
        int mod = (int)1e9+7;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            StringBuilder a = new StringBuilder(String.valueOf(nums[i]));
            rev[i] = Integer.parseInt(a.reverse().toString());
            nums[i] = nums[i]-rev[i];
            map.put(nums[i],map.getOrDefault(nums[i],0)+1);
        }
        long res = 0;
        for (Integer integer : map.keySet()) {
            long x = map.get(integer);
            res+=x*(x-1)/2%mod;
        }
        return (int)res;
    }
    public static void main(String[] args) {
        Ex5708 ex5708 = new Ex5708();
        int[] a = {42,11,1,97};
        ex5708.countNicePairs(a);
    }
}